<template>
  <div v-loading="loading">
    <!--<el-button type="primary" size="small" round style="margin-top: 10px" @click="handleOpenAuth(2)">授权小程序</el-button>-->

    <!--空-->
    <div v-for="(v,k) in classifyCodeStatusOptions" :key="k">
      <el-card v-if="!v.status" :body-style="{ padding: '20px 15px'}" class="card-container">
        <div class="empty-container flex-y-center-center">
          <i class="el-icon-plus" />
          <div class="tips">{{ v.name }}暂未授权</div>
          <el-button type="primary" round size="small" @click="handleOpenAuth(2,'MCH_ASSIST')">去授权</el-button>
        </div>
      </el-card>
    </div>

    <!--列表-->
    <el-card v-for="item in list" :key="item.appId" :body-style="{ padding: '20px 15px'}" class="card-container">
      <div class="flex-x-start">
        <div class="left-container">
          <el-image
            class="logo"
            :src="item.info.headImg"
            fit="fill"
          />
        </div>
        <div class="right-container">
          <div class="flex-x-between-center">
            <div class="name">{{ item.info.nickName }}</div>
            <div>
              <el-button type="primary" size="small" round @click="handleOpenAuth(2,'MCH_ASSIST')">
                重新授权
              </el-button>
              <!--<el-button type="primary" size="small" round @click="handleRefresh(item.recordId)">刷新</el-button>-->
            </div>
          </div>
          <el-form label-width="100px" label-position="left" size="small">
            <el-form-item label="绑定应用：">
              <el-tag>品牌小程序</el-tag>
            </el-form-item>
            <el-form-item label="appId：">
              {{ item.base.appId }}
            </el-form-item>
            <el-form-item label="原始ID：">
              {{ item.base.userName }}
            </el-form-item>
            <el-form-item label="已授权权限：">
              {{ item.permsStr }}
            </el-form-item>
            <el-form-item v-if="item.missingPermsStr" label="缺少权限：">
              {{ item.missingPermsStr }}
            </el-form-item>
            <el-form-item v-if="item.state === 0" label="授权异常：">
              <span class="app-color-danger">{{ item.base.remark || '-' }}</span>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-card>

    <!--组件-->
    <WechatAuthQrcodeDialog ref="wechatAuthQrcodeDialog" />
  </div>
</template>

<script>
import WechatAuthQrcodeDialog from './WechatAuthQrcodeDialog'
import { authMaInfo } from '@/api/wechat'

export default {
  components: {
    WechatAuthQrcodeDialog
  },
  data() {
    return {
      // 配置
      classifyCodeStatusOptions: {
        MCH_ASSIST: {
          name: '品牌小程序',
          status: false
        }
      },
      // 状态
      loading: false,
      // 数据
      list: []
    }
  },
  computed: {},
  watch: {},
  beforeCreate() {
  },
  created() {
  },
  beforeMount() {
  },
  mounted() {
    this.fetchData()
  },
  beforeUpdate() {
  },
  update() {
  },
  activated() {
  },
  deactivated() {
  },
  beforeDestroy() {
  },
  destroyed() {
  },
  methods: {
    /**
     * 数据组
     */
    // 获取数据
    fetchData() {
      this.loading = true
      authMaInfo({ params: { classifyCode: 'MCH_ASSIST' } }).then(res => {
        // const list = res.data || []
        // if (v.relation && v.relation.classifyCode && Object.keys(this.classifyCodeStatusOptions).includes(v.relation.classifyCode)) {
        //   this.classifyCodeStatusOptions[v.relation.classifyCode].status = true
        // }
        this.classifyCodeStatusOptions['MCH_ASSIST'].status = !!res.data
        this.list = res.data ? [res.data] : []
      }).finally(() => {
        this.loading = false
      })
    },

    /**
     * 按钮组
     */
    // 授权小程序
    handleOpenAuth(authType, classifyCode = null) {
      this.$refs.wechatAuthQrcodeDialog.open(authType, classifyCode).then(res => {
        this.fetchData()
      })
    }
    //
    // handleRefresh(recordId) {
    //   this.loading = true
    //   refreshMp({ params: { recordId } }).then(res => {
    //     this.fetchData()
    //     this.$notify({
    //       title: '成功',
    //       message: '刷新成功',
    //       type: 'success',
    //       duration: 2000,
    //       offset: 40
    //     })
    //   }).finally(() => {
    //     this.loading = false
    //   })
    // }

    // 申请授权
    // handleClassifyCodeAuthUrl(authType, classifyCode) {
    //   const cb = location.protocol + '//' + location.host + '/#/system/platform-setting'
    //   wechatAuthUrl({ params: { authType, cb, classifyCode } }).then(res => {
    //     window.location.href = res.data.url
    //   })
    // }
    /**
     * 状态组
     */
    /**
     * 方法组
     */
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
//.empty-tips {
//  text-align: center;
//  font-size: 12px;
//  padding-top: 100px;
//}

.empty-container {
  height: 150px;
  .tips {
    margin: 10px;
    font-weight: bold;
  }
  .el-icon-plus {
    margin-top: 10px;
    font-size: 50px;
  }
}

/*容器*/
.card-container {
  margin-top: 10px;
}

/*左边*/
.left-container {
  margin-right: 20px;

  .logo {
    height: 80px;
    width: 80px;
  }

  .el-icon-picture-outline {
    font-size: 80px;
  }
}

/*右边*/
.right-container {
  .name {
    font-size: 22px;
    font-weight: bold;
  }

  .el-form-item--small.el-form-item {
    margin-bottom: 0;
  }
}
</style>
